package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 供应商实现类
 */
@Service
@Transactional
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private ISupplierMapper supplierMapper;
    @Override
    public IPage<SupplierBean> findByItem(Integer pageNO, String name, String manage) {
        QueryWrapper<SupplierBean> qw = new QueryWrapper<>();
        if (name!=null&&name.length()!=0){
            qw.like("s_name",name);
        }
        if (manage!=null&&manage.length()!=0){
            qw.like("s_manage",manage);
        }
        return supplierMapper.selectPage(new Page(pageNO,3),qw);
    }

    @Override
    public void add(SupplierBean supplierBean) {
        supplierMapper.insert(supplierBean);
    }

    @Override
    public SupplierBean findById(Integer id) {
        return supplierMapper.selectById(id);
    }

    @Override
    public void update(Integer id, String principal, String phone) {
        SupplierBean supplierBean = supplierMapper.selectById(id);
        supplierBean.setPrincipal(principal);
        supplierBean.setPhone(phone);
        supplierMapper.updateById(supplierBean);
    }

    @Override
    public List<SupplierBean> find() {
        return supplierMapper.selectList(null);
    }

    @Override
    public void addList(List<SupplierBean> supplierList) {
        supplierMapper.addList(supplierList);
    }
}
